package wrs.hcs.functions;

import java.io.FileInputStream;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.concurrent.TimeUnit;

import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

import org.openqa.selenium.WebDriver;

public class Miscellaneous {

	public void goto_wellness_webapp(WebDriver driver){
		driver.manage().window().maximize();
		String wrs = "http://eorder-qa.stlukesmedicalcenter.com.ph/ereserve/wellnessReservation.html";
		driver.get(wrs);
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
	}

	public String get_xls_details() throws BiffException, IOException{
		
		String workingDir = System.getProperty("user.dir");
		FileInputStream f2 = new FileInputStream(workingDir+"\\excel\\email.xls"); 
		Workbook wb = Workbook.getWorkbook(f2);
		Sheet sheet = wb.getSheet(0);
		String email = sheet.getCell(0,0).getContents().trim();
		return email;
		
	}
	
	public String set_package_id(String new_package){
		String package_set = "";
		if(new_package.equals("basic")){
			package_set = "PACKBASC";
		}else if(new_package.equals("cardiometabolic")){
			package_set = "PACKCARDIO";
		}else if(new_package.equals("diabetes")){
			package_set = "PACKDIAB";
		}else if(new_package.equals("golden")){
			package_set = "PACKGOLDEN";
		}else if(new_package.equals("overweight")){
			package_set = "PACKOVRWEIGHT";
		}
		return package_set;
	}
	
	public String set_date_webapp(){
		
		DateFormat cd = new SimpleDateFormat("MM/dd/yyyy");
        Date current = Calendar.getInstance().getTime();
		String dateToday = cd.format(current);
		String new_date[] = dateToday.split("/"); 			//split date
		int intMonth= Integer.parseInt(new_date[0]);
		int intYear= Integer.parseInt(new_date[2]);
		if(intMonth!=12){
			intMonth = intMonth+1;
		}else{
			intYear = intYear+1;
			intMonth=1;
		}
		String strMonth = Integer.toString(intMonth);
		String strYear = Integer.toString(intYear);
		String finalDateInput = strMonth+"/"+new_date[1]+"/"+strYear;
		
		return finalDateInput;
	}
	
	public String set_current_date_plus_one(){
		
		DateFormat cd = new SimpleDateFormat("MM/dd/yyyy");
        Date current = Calendar.getInstance().getTime();
		String dateToday = cd.format(current);
		String new_date[] = dateToday.split("/"); 			//split date
		int intDay= Integer.parseInt(new_date[1]);
		int intMonth= Integer.parseInt(new_date[0]);
		int intYear= Integer.parseInt(new_date[2]);
		if(intMonth==2){
			if(intDay>=28){
				intMonth = intMonth+1;
				intDay=1;
			}else{
				intDay = intDay+1;
			}
		}else{
			if(intDay>30){
				if(intMonth==12){
					intYear = intYear +1;
					intMonth=1;
					intDay =1;
				}else{
					intMonth = intMonth+1;
					intDay=1;
				}
			}else{
				intDay = intDay+1;
			}
		}
		String strMonth = Integer.toString(intMonth);
		String strYear = Integer.toString(intYear);
		String strDay = Integer.toString(intDay);
		String finalDateInput = strMonth+"/"+strDay+"/"+strYear;
		
		return finalDateInput;
	}

	public String set_dropdown_to_hcs(String text){
		
		String dropdown_command = "";
		if(text.equals("cancel")){
			dropdown_command = "CANCEL SELECTED RESERVATION";
		}else if(text.equals("outpatient")){
			dropdown_command = "FORWARD OUTPATIENT TO HCS";
		}else if(text.equals("online")){
			dropdown_command = "FORWARD PAYMENT RECORD TO HCS";
		}else if(text.equals("admission")){
			dropdown_command = "FORWARD TO ADMISSION DEPARTMENT";
		}else if(text.equals("queue")){
			dropdown_command = "QUEUE SELECTED TO HCS";
		}else if(text.equals("reactivate")){
			dropdown_command = "REACTIVATE SELECTED RESERVATION";
		}else if(text.equals("tracker")){
			dropdown_command = "TRANSFER RECORD(s) TO RESULTS TRACKER";
		}
		return dropdown_command;
		
	}
	
	public void refresh_window(WebDriver driver){
		driver.navigate().refresh();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
	}
	
}
